<template>
    <div id="app">
      <el-form :model="bookLaboratory" label-width="100px"  ref="abc">
        <el-form-item label="预定的实验室" prop="lid">
          <el-select v-model="bookLaboratory.lid" placeholder="请选择">
            <el-option
              v-for="item in laboratoryList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="开始时间" prop="startDate">
          <el-date-picker
            v-model="bookLaboratory.startDate"
            type="datetime"
            placeholder="选择开始时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="结束时间" prop="endDate">
          <el-date-picker
            v-model="bookLaboratory.endDate"
            type="datetime"
            placeholder="选择开始时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="预定的老师" prop="tid">
          <el-select v-model="bookLaboratory.tid" placeholder="请选择">
            <el-option
              v-for="item in teacherList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="预定原因" prop="bookReason">
          <el-input v-model="bookLaboratory.bookReason"  type="textarea" rows="5"></el-input>
        </el-form-item>

        <el-form-item label="描述" prop="description">
          <el-input v-model="bookLaboratory.description"  type="textarea" rows="5"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click.prevent="test">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
    export default {
      data(){
        return {
          bookLaboratory:{
          },
          teacherList:[],
          laboratoryList:[]
        }
      },
      created() {
        this.axios.get("/teacher/selectAll").then((resp)=>{
          this.teacherList=resp.data;
        });
        this.axios.get("/laboratory/selectAll").then((resp)=>{
          this.laboratoryList=resp.data;
        });
    },
      methods:{
        test(){
          this.$refs["abc"].validate((valid)=>{
            //valid表示表单是否验证通过。
            if(valid){
              //发出保存请求
              this.$confirm("是否确认提交","保存提示").then(()=>{
                this.axios.post("/bookLaboratory/add",this.bookLaboratory).then((resp)=>{
                    this.$message.success("保存成功！");
                    this.$router.push("/bookLaboratory/selectAll")
                  });
              }).catch(()=>{});

            }
          })
        }
      }
    }
</script>


<style scoped>

</style>
